var express = require("express");
var router = express.Router();
// 可以接受图片
const multiparty = require("multiparty");

// 配置图片上虚拟路由
router.use("/uploads/Chatpicture", express.static("uploads/Chatpicture"));


// 上传图片
router.post('/myupload', (req, res) => {
  let form = new multiparty.Form()
  form.uploadDir = "uploads/Chatpicture";
  form.parse(req, (err, formData, imgData) => {
    console.log(`imgData`, imgData);
    // 将上传的图片传递给前端
    let ert = imgData.file[0].path.replace(/\\/g,'/',2);
    res.send({
      path: ert
    })
  })
})

module.exports = router;
